<?php
global $Config;
require_once($Config->WebCMSRoot.'Base/View.php');

Class ContentView extends BaseView
{
	function ContentView()
	{
		parent::BaseView();
	}
	
	function ShowContent($content)
	{
//print('<pre>'.var_export($content, true).'</pre>');exit;
//print('<pre>'.var_export($this, true).'</pre>');exit;
		$contentID = -1;

		$output = '';
		if ($content->ID == '')
		{
			$id = md5(uniqid($this->User->ID));
	  		/*if (isset($this->User)) // && $this->User->EditMode
	  		{
	  			$output = 'Double click here to enter content.';
	  		}*/
		}
		else
		{
			$output = $content->Content;
			$output = utf8_encode($output);
			$id = md5($content->Key.'|'.$this->User->ID);
			$contentID = $content->ID;
		}

/* Disabled: not complete & moved to console
		if (isset($this->User)) // && $this->User->EditMode
		{
		
			//$this->output  = '<div class="editable" ondblclick="EditContent('.$contentID.', \''.$key.'\', this);" id="'.$id.'">';
			//$this->output  = '<div class="editable" ondblclick="RefreshEditor();" id="'.$id.'" title="Double-click to edit">';
			$this->output  = '<div class="editable" ondblclick="EditContent('.$contentID.', \''.$content->Key.'\', $(\''.$id.'\'));" id="'.$id.'" title="Double-click to edit">';
			$this->output .= $output;
			$this->output .= '</div>'."\n";
			//$this->output .= '<script type="text/javascript" type="text/javascript">'."\n";
			//$this->output .= 'function RefreshEditor() {EditContent('.$contentID.', \''.$content->Key.'\', $(\''.$id.'\'))};'."\n";
			//$this->output .= '</script>'."\n";
			
			$this->output .= '<div id="commands_'.$id.'" class="commandBar">';
			$this->output .= '		<p><a href="javascript:void(0);" onclick="ContentPreview();">Preview</a></p>'."\n";
			$this->output .= '		<p><a href="javascript:void(0);" onclick="ContentSave();">Bewaren</a></p>'."\n";
			$this->output .= '		<p><a href="javascript:void(0);" onclick="ContentClose();">Sluiten</a></p>'."\n";
			$this->output .= '		<a href="javascript:void(0);" onclick="dockTop();" title="Dock Top">^</a>'."\n";
			$this->output .= '		<a href="javascript:void(0);" onclick="dockRight();" title="Dock Right">&gt;</a>'."\n";
			$this->output .= '		<a href="javascript:void(0);" onclick="dockLeft();" title="Dock Left">&lt;</a>'."\n";
			$this->output .= '		<a href="javascript:void(0);" onclick="dockBottom();" title="Dock Bottom">-</a>'."\n";
			$this->output .= '</div>';

			$this->output .= '<div class="editor" id="editor_'.$id.'">';
			$this->output .= '<script language="javascript" type="text/javascript" src="/assets/WebCMS/mootools.js"></script>'."\n";
			$this->output .= '<script type="text/javascript" type="text/javascript">'."\n";
			$this->output .= '_editor_url  = "/assets/WebCMS/xinha/"  // (preferably absolute) URL (including trailing slash) where Xinha is installed'."\n";
			$this->output .= '_editor_lang = "en";      // And the language we need to use in the editor.'."\n";
			$this->output .= 'window.onload=initEditor(\''.$id.'\');'."\n";
			$this->output .= '</script>'."\n";
			$this->output .= '<script type="text/javascript" src="/assets/WebCMS/xinha/htmlarea.js"></script>'."\n";
			$this->output .= '<script type="text/javascript" src="/assets/WebCMS/xinha/my_config.js"></script>'."\n";
			$this->output .= '<textarea id="xinha1" name="xinha1" rows="10" cols="50" style="width: 100%">' . $output . '</textarea>'."\n";
			$this->output .= '	<div class="contentCommand">'."\n";
			$this->output .= '		<a href="javascript:void(0);" onclick="ContentPreview();">Preview</a>'."\n";
			$this->output .= '		<a href="javascript:void(0);" onclick="ContentSave();">Bewaren</a>'."\n";
			$this->output .= '		<a href="javascript:void(0);" onclick="ContentClose();">Sluiten</a>'."\n";
			$this->output .= '	</div>'."\n";
			$this->output .= '</div>'."\n";
		}
		else
		{
*/
//print('<pre>'.var_export($content, true).'</pre>');exit;
			$this->output = $output;
/*		}*/
	}

	function ClientSideTemplates()
	{
		$templates = array(
			'content' => array(
				'overview' => '<div class="overview_item">'.
							  '<div class="overviewTitle">[$Key$]</div>'.
							  '<div id="overviewDetails_[$ID$]" class="overviewDetails">[$Content$]<br />'.
				              '<div class="overview_actions">'.
							  '<a href="#" onClick="Content_Edit_Item([$ID$])">Bewerken</a>'.
							  '<a href="#" onClick="confirm(\'Bent u zeker dat u \\\'[$Key$]\\\' wilt verwijderen?\', function() { Content_Delete_Item([$ID$]); } )">Verwijderen</a>'.
							  '</div>',
							  '</div>',
							  '</div>',
				'edit' => '<div class="edit_item form">'.
						  '<div class="formFieldLabel"><label for="contentKey">Key:</label></div>'.
						  '<div class="formFieldEntry"><input type="text" value="[$Key$]" id="contentKey" name="contentkey" maxlength="100" size="50" /></div>'.
						  '<textarea id="contentHTML" name="contentHTML" class="fck" cols="50" rows="6">[$Content$]</textarea>'.
				          '<div class="overview_actions">'.
						  '<a href="#" onClick="Content_Overview()">Annuleren</a> '.
						  '<a href="#" onClick="Content_Save([$ID$])">Opslaan</a> '.
						  '<a href="#" onClick="confirm(\'Bent u zeker dat u \\\'[$Key$]\\\' \\n\\nwilt verwijderen?\', function() { Content_Delete_Item([$ID$]); } )" id="btnContent_Edit_Delete">Verwijderen</a> '.
						  '</div>',
						  '</div>'/*,
				'photos' => '<div class="edit_item form">'.
						    '<h2>[$Title$]</h2>'.
						    '[$Description$]<br /><br />'.
						    '<div>{#template_koopje_images#}</div>'.
				            '<div class="overview_actions">'.
						    '<a href="#" onClick="Content_Overview()">Annuleren</a> '.
						    '<a href="#" onClick="Content_Photo_Add([$ID$], adminRoot + \'koopjes/imageUpload/[$ID$]\')">Toevoegen</a> '.
						    '</div>',
						    '</div>',
				'thumbnail' => '<div class="edit_thumbnail">'.
						  '<img s_rc="[$Thumbnail$]" alt="[$File$]" /><br />'.
						  '[$File$]'.
						  '</div>',
				'managephotos' => '<div class="edit_thumbnail">'.
						  '<img s_rc="[$Thumbnail$]" alt="[$File$]" /><br />'.
						  '[$File$]<br />'.
						  '<a href="#" class="button" onClick="confirm(\'Bent u zeker dat u deze foto wilt verwijderen?\', function() { Content_Photos_Delete([$ID$], [$_parentID$]); } )">Verwijder</a>'.
						  '</div>'*/
			)
		);
		$this->JsonOutput($templates);
	}
}
?>